home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 41 / Issue 41.iso / pc / PCSoftware / Netscape 6 Official Release / nim.xpi / bin / chrome / aim.jar / content / aim / App.js < prev    next >
Encoding:
Text File  |  2000-09-26  |  30.3 KB  |  1,112 lines

  1.  
  2. var AimSessionObserver = new Object();
  3.  
  4.  
  5. // XXX Global to determine if our onload handler has been called yet.
  6. // For some reason, our onunload handler is getting called before onload
  7. // on the first time we create App.xul. This is a workaround.
  8. var gFirstTime = 1;
  9.  
  10. AimSessionObserver.onAssert = function(datasource, source, property, target) {
  11.     if (source.EqualsNode(AimSession)) {
  12.         if (property.EqualsNode(SessionState)) {
  13.             var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  14.             var signonItem = top.document.getElementById("miSignOn");
  15.             var signoffcloseItem = top.document.getElementById("miSignOffClose");
  16.             var peopleMenu = top.document.getElementById("people_menu");
  17.             var newIMMenu = top.document.getElementById("menu_newIM");
  18.             var importBuddyMenu = top.document.getElementById("miImportBuddyList");
  19.             var exportBuddyMenu = top.document.getElementById("miExportBuddyList");
  20.  
  21.  
  22.             if (state == "Register")
  23.             {
  24.                 top.title = aimString("app.title.Register");
  25.                 signonItem.setAttribute("value", aimString("miSignOn.SignOn"));
  26.                 signonItem.setAttribute("disabled", "true");
  27.                 signoffcloseItem.setAttribute("disabled", "true");
  28.                 peopleMenu.setAttribute("disabled", "true");
  29.                 newIMMenu.setAttribute("disabled", "true");
  30.                 importBuddyMenu.setAttribute("disabled", "true");
  31.                 exportBuddyMenu.setAttribute("disabled", "true");
  32.             }
  33.             else if (state == "Offline") {
  34.                 top.title = aimString("app.title.SignOn");
  35.                 signonItem.setAttribute("value", aimString("miSignOn.SignOn"));
  36.                 signonItem.setAttribute("oncommand", "cmdSignOn();");
  37.                 signoffcloseItem.setAttribute("disabled", "true");
  38.                 signonItem.setAttribute("disabled", "false");
  39.                 peopleMenu.setAttribute("disabled", "true");
  40.                 newIMMenu.setAttribute("disabled", "true");
  41.                 importBuddyMenu.setAttribute("disabled", "true");
  42.                 exportBuddyMenu.setAttribute("disabled", "true");
  43.             }
  44.             else if (state == "Online") {
  45.                 top.title = aimString("app.title.Online").replace(/%UserName%/, aimSessionCurrentScreenName());
  46.                 signonItem.setAttribute("value", aimString("miSignOn.SignOff"));
  47.                 signonItem.setAttribute("oncommand", "cmdSignOff();");
  48.                 signonItem.setAttribute("disabled", "false");
  49.                 signoffcloseItem.setAttribute("disabled", "false");
  50.                 peopleMenu.setAttribute("disabled", "false");
  51.                 newIMMenu.setAttribute("disabled", "false");
  52.                 importBuddyMenu.setAttribute("disabled", "false");
  53.                 exportBuddyMenu.setAttribute("disabled", "false");
  54.                 aimMigrateBuddyList( aimSessionCurrentScreenName() );
  55.             }
  56.             else if (state == "OnlineAway") {
  57.                 top.title = aimString("app.title.OnlineAway");
  58.                 signonItem.setAttribute("value", aimString("miSignOn.SignOff"));
  59.                 signonItem.setAttribute("oncommand", "cmdSignOff();");
  60.                 signonItem.setAttribute("disabled", "false");
  61.                 signoffcloseItem.setAttribute("disabled", "false");
  62.                 peopleMenu.setAttribute("disabled", "false");
  63.                 newIMMenu.setAttribute("disabled", "false");
  64.                 importBuddyMenu.setAttribute("disabled", "false");
  65.                 exportBuddyMenu.setAttribute("disabled", "false");
  66.             }
  67.             else {
  68.                 top.title = aimString("app.title.Connecting");
  69.                 signonItem.setAttribute("value", aimString("miSignOn.Cancel"));
  70.                 signonItem.setAttribute("oncommand", "cmdCancelSignOn();");
  71.                 signoffcloseItem.setAttribute("disabled", "true");
  72.                 peopleMenu.setAttribute("disabled", "true");
  73.                 newIMMenu.setAttribute("disabled", "true");
  74.                 importBuddyMenu.setAttribute("disabled", "true");
  75.                 exportBuddyMenu.setAttribute("disabled", "true");
  76.             }
  77.         }
  78.     }
  79. };
  80.  
  81. AimSessionObserver.onUnassert = function(datasource, source, property, target) {};
  82.  
  83. AimSessionObserver.onChange = function(datasource, source, property, oldTarget, newTarget) {
  84.     AimSessionObserver.onAssert(datasource, source, property, newTarget);
  85. };
  86.  
  87. AimSessionObserver.onMove = function(datasource, oldSource, newSource, property, target) {
  88.     AimSessionObserver.onAssert(datasource, newSource, property, target);
  89. };
  90.  
  91. AimSessionObserver.beginUpdateBatch = function(datasource) {
  92. };
  93.  
  94. AimSessionObserver.endUpdateBatch = function(datasource) {
  95. };
  96.  
  97. /*
  98. function ComeBack()
  99. {
  100.     locateManager = aimLocateManager();
  101.  
  102.     if ( locateManager ) {
  103.         locateManager.SetUserInfoAwayMessage(null);
  104.     }
  105. }
  106. */
  107.  
  108. function getsidebarframe()
  109. {
  110.     var frame_list=window.frames;
  111.      if (frame_list.length==0)
  112.           return window;
  113.       
  114.      for (i=0; i<frame_list.length; i++) {
  115.      if (frame_list[i].location =="chrome://aim/content/Sidebarpanel.xul");
  116.          return frame_list[i];
  117.          }
  118.      
  119. }
  120.  
  121.  
  122. function GoAway( target )
  123. {
  124.     var name = target.getAttribute('MsgText');
  125.     if(name==''){
  126.         try{
  127.         name= document.getElementById('tbAway').getElementsByTagName("menuitem")[1].getAttribute('MsgText')
  128.         }
  129.         catch (e) {
  130.             dump("goAway(): Some error finding tbAway message!\n Setting default backup message.\n");
  131.             name=aimString("away.DefaultMessage");
  132.         }
  133.     }
  134.     else{
  135.         //dump("goaway: msgText: "+name+" \n");
  136.     }
  137.     
  138.  
  139.     locateManager = aimLocateManager();
  140.  
  141.     if ( locateManager )
  142.         locateManager.SetUserInfoAwayMessage(name);
  143. }
  144.  
  145. var targetElement = null;
  146.  
  147. function GoAwayWait(target,wait){
  148.     targetElement=target
  149.     setTimeout('GoAway( targetElement )',wait)
  150. }
  151.  
  152. /*
  153.  * Function: AimAppOnWndLoad()
  154.  *
  155.  * Arguments: None
  156.  * 
  157.  * Return: None
  158.  *
  159.  * Description: Called once app.xul has finished loading. Adds observer 
  160.  *         AimSessionObserver to the AimDataSource. Initializes the
  161.  *        sidebar.
  162. */
  163.  
  164. var RDF = null;
  165.  
  166. function GetRDFService()
  167. {
  168.         if ( RDF == null ) {
  169.                 var RDFClass = Components.classes['@mozilla.org/rdf/rdf-service;1'];
  170.                 RDF = RDFClass.getService(Components.interfaces.nsIRDFService);
  171.         }
  172. }
  173.  
  174. function AimAppOnWndLoad()
  175. {
  176.     HideMenus();
  177.     
  178. //    dump("AimAppOnWndLoad()\n");
  179.  
  180.     // XXX See note at the top of the file
  181.     gFirstTime = 0;
  182.  
  183.     // Initialize for current online state
  184.     var state = AimDataSource.GetTarget(AimSession, SessionState, true);
  185.     if (state == null)
  186.         state = RDF.GetLiteral("Register");
  187.  
  188.     AimSessionObserver.onAssert(AimDataSource, AimSession, SessionState, state);
  189.     AimDataSource.AddObserver(AimSessionObserver);
  190.  
  191.     //if ((window.arguments) && (window.arguments[0] == "Setup"))
  192.         //AimWindowLoad2(window);
  193.  
  194.   GetRDFService();
  195.   var sidebar_file = GetAwayMessagesFileLoc();
  196.   var datasource = RDF.GetDataSource(sidebar_file);
  197.  
  198.   var menu = document.getElementById("awayMenu");
  199.   menu.database.AddDataSource(datasource);
  200.   menu.setAttribute('ref', menu.getAttribute('ref'));
  201.   
  202.   menu = document.getElementById("tbAway");
  203.   menu.database.AddDataSource(datasource);
  204.   menu.setAttribute('ref', menu.getAttribute('ref'));
  205.  
  206.   setTimeout("CheckBuddyPanel()",500);
  207.  
  208.   setAdTimer();
  209. }
  210.  
  211. function HideMenus()
  212. {
  213.     var menu;
  214.     
  215.     if ( aimIsShrimp() == true ) {
  216.         menu=document.getElementById('menu_Help');
  217.         if(menu != null && menu != undefined)
  218.             menu.setAttribute("hidden", "true");
  219.     } else {
  220.         menu=document.getElementById('menu-services');
  221.         if(menu != null && menu != undefined)
  222.             menu.setAttribute("hidden", "true");
  223.         menu=document.getElementById('menu-actions');
  224.         if(menu != null && menu != undefined)
  225.             menu.setAttribute("hidden", "true");
  226.         menu=document.getElementById('menu-ShrimpHelp');
  227.         if(menu != null && menu != undefined)
  228.             menu.setAttribute("hidden", "true");
  229.     }
  230. }
  231.  
  232. /*
  233.  * Function: AimAppOnWndUnload()
  234.  *
  235.  * Arguments: None
  236.  * 
  237.  * Return: None
  238.  *
  239.  * Description: Called once app.xul has been unloaded. Removes observer 
  240.  *         AimSessionObserver from the AimDataSource. 
  241. */
  242.  
  243. function AimAppOnWndUnload()
  244. {
  245. //    dump("AimAppOnWndUnload()\n");
  246.     // XXX See note at the top of the file
  247.     if(gFirstTime == 1)
  248.         return;
  249.  
  250.     AimDataSource.RemoveObserver(AimSessionObserver);
  251. }
  252.  
  253. function AimAppOnSidebarTabChange()
  254. {
  255.     dump("OnSidebarTabChange()\n");
  256. }
  257.  
  258. function AimAppPeopleMenuSwitch(tabValue)
  259. {
  260.     dump("PeopleMenuSwitch()\n");
  261. }
  262.  
  263. //************  Command Handling ****************
  264.  
  265. /*
  266.  * Function: cmdNewBrowser()
  267.  *
  268.  * Arguments: None
  269.  * 
  270.  * Return: None
  271.  *
  272.  * Description: Function invoked from menu or toolbar to create a new 
  273.  *         browser window. 
  274.  * 
  275.  * Bugs: URL is hardcoded. Needs to open a user-specified preference.
  276. */
  277.  
  278. function cmdNewBrowser()
  279. {
  280.     aimCmdNewBrowser("http://home.netscape.com");
  281. }
  282.  
  283. /*
  284.  * Function: cmdNewEmail()
  285.  *
  286.  * Arguments: None
  287.  * 
  288.  * Return: None
  289.  *
  290.  * Description: Function invoked from menu or toolbar to create a new
  291.  *        messenger window. 
  292. */
  293.  
  294. function cmdNewEmail()
  295. {
  296.     aimCmdNewEmail();
  297. }
  298.  
  299.  
  300.  
  301.  function cmdNewChat(invScreenName,invProposal,invScreenNames,toExistingWindow,invMode){
  302.  
  303.       inviteArgsObj = {
  304.           inviteProposalScreenName: invScreenName, 
  305.           inviteProposalObj: invProposal,
  306.           invitedScreenNames: invScreenNames,
  307.           inviteToExistingWindow: toExistingWindow,
  308.           inviteMode: invMode
  309.           }
  310. window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  311. }
  312.  
  313.  
  314. /*
  315.  * Function: cmdNewIM()
  316.  *
  317.  * Arguments: None
  318.  * 
  319.  * Return: None
  320.  *
  321.  * Description: Function invoked from menu or toolbar to create a new IM 
  322.  *        window. Loads the window into a pre-connect state, e.g., the 
  323.  *        dialog consists of screen name field and an editor. This
  324.  *        function determines which buddy is selected in the list. 
  325.  *        If a buddy is selected (the first one found) and is online,
  326.  *        the screenname field in the IM window is initialized to that
  327.  *        buddy. Otherwise, the screen name field is set to "".
  328. */
  329.  
  330. function cmdNewIM()
  331. {
  332.     var buddies = getSelectedBuddiesFromList();
  333.     if ( AimOnlineAway() )
  334.         ComeBack();
  335.     aimIMInvokeIMForm(buddies[0], null);
  336. }
  337.  
  338. /*
  339.  * Function: getSelectedBuddiesFromList()
  340.  *
  341.  * Arguments: None
  342.  * 
  343.  * Return: array of strings of buddies
  344.  *     that are currently selected (expands Groups to all buddies in group).
  345.  *
  346.  * Description: Function invoked via cmdNewIM and cmdNewChatSidebar to poll the
  347.  *        Buddy list to find out which buddies (and expanded groups are selected).
  348.  *        This function will always return an Array, the first element will
  349.  *        be null if there was a problem, or no buddies selected.
  350.  *    
  351. */
  352.  
  353. function getSelectedBuddiesFromList()
  354. {
  355.     selectedBuddies = new Array();
  356.     var l = 0;  //Keep track of the selectedBuddies array.
  357.     var sidebarframe=getsidebarframe();
  358.         
  359.     var selectedGroup = "";
  360.     var wasSelected = false;
  361.  
  362.     var tree = sidebarframe.document.getElementById("OnlineBuddies");
  363.     var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  364.  
  365.     if (!tab)
  366.         return selectedBuddies;
  367.     if (!tree )
  368.         return selectedBuddies;
  369.  
  370.     // in the ListSetup tab and the user tries to sendIM or Chat
  371.     if ( tab.getAttribute('index') == 1 )
  372.         {
  373.         return selectedBuddies;
  374.         }
  375.  
  376.     // Loop through all the buddies to see which one they want to
  377.     // send an IM to.  If they have not selected anyone, or if they
  378.     // have selected a group, bring up a blank IM send window.
  379.  
  380.     var groups = aimBuddyTreeFindGroups(tree);
  381.     
  382.     if ( groups ) {
  383.         for (var i = 0; i != groups.length; i++) 
  384.             {
  385.             if (groups[i].getAttribute("selected") == "true") 
  386.                 {
  387.                 groups[i].setAttribute("open", true);
  388.                 selectedGroup = groups[i].getAttribute("Name");
  389.                 if ( selectedGroup != null && selectedGroup != "" ) 
  390.                     {
  391.                     wasSelected = true;
  392.  
  393.                     // find the buddies in the data source that
  394.                     // correspond to the current group in the loop
  395.  
  396.                     var buddies = null;
  397.                     for (var j = 0; j != groups[i].childNodes.length; j++)
  398.                     {
  399.                         if (groups[i].childNodes[j].nodeName == "treechildren")
  400.                         {
  401.                             buddies = groups[i].childNodes[j].childNodes;
  402.                             break;
  403.                         }
  404.                     }
  405.                     if (buddies) {
  406.                         for (var k = 0; k != buddies.length; k++) {
  407.                             selectedBuddies[l++] = buddies[k].getAttribute("ScreenName");
  408.                         }
  409.                     }
  410.                     }
  411.                 }
  412.             else 
  413.                 {
  414.  
  415.                 // find the buddies in the data source that
  416.                 // correspond to the current group in the loop
  417.  
  418.                 var buddies = null;
  419.                 for (var j = 0; j != groups[i].childNodes.length; j++)
  420.                 {
  421.                     if (groups[i].childNodes[j].nodeName == "treechildren")
  422.                     {
  423.                         buddies = groups[i].childNodes[j].childNodes;
  424.                         break;
  425.                     }
  426.                 }
  427.  
  428.                 if (buddies)
  429.                 {
  430.                     // we found the buddies, now see if we
  431.                     // can find a selected one
  432.  
  433.                     for (var k = 0; k != buddies.length; k++)
  434.                     {
  435.                         if (buddies[k].getAttribute("selected") == "true")
  436.                         {
  437.                             selectedBuddy = buddies[k].getAttribute("ScreenName");
  438.                             if ( selectedBuddy && selectedBuddy != "" ) {
  439.                                 // found a selected buddy. If there
  440.                                 // is a window already, display an 
  441.                                 // error message, else create a new one
  442.  
  443.                                 wasSelected = true;
  444.                                 selectedBuddies[l++] = selectedBuddy;
  445.                             }                    
  446.                         }
  447.                     }
  448.                 }
  449.             }
  450.         }
  451.     }
  452.     return selectedBuddies;
  453. }
  454.  
  455. /*
  456.  * Function: cmdLoadBuddyList()
  457.  *
  458.  * Arguments: None
  459.  * 
  460.  * Return: None
  461.  *
  462.  * Description: Unimplemented. See bugsplat 361248
  463. */
  464.  
  465. function cmdLoadBuddyList()
  466. {
  467.     dump("Implement Menu Command cmdLoadBuddyList()\n");
  468. }
  469.  
  470. /*
  471.  * Function: cmdSaveBuddyList()
  472.  *
  473.  * Arguments: None
  474.  * 
  475.  * Return: None
  476.  *
  477.  * Description: Unimplemented. See bugsplat 361248 
  478. */
  479.  
  480. function cmdSaveBuddyList()
  481. {
  482.     dump("Implement Menu Command cmdSaveBuddyList()\n");
  483. }
  484.  
  485. /*
  486.  * Function: cmdSendFile()
  487.  *
  488.  * Arguments: None
  489.  * 
  490.  * Return: None
  491.  *
  492.  * Description: Unimplemented
  493. */
  494.  
  495. function cmdSendFile()
  496. {
  497.     dump("Implement Menu Command cmdSendFile()\n");
  498. }
  499.  
  500. /*
  501.  * Function: cmdGetFile()
  502.  *
  503.  * Arguments: None
  504.  * 
  505.  * Return: None
  506.  *
  507.  * Description: Unimplemented
  508. */
  509.  
  510. function cmdGetFile()
  511. {
  512.     dump("Implement Menu Command cmdGetFile()\n");
  513. }
  514.  
  515. /*
  516.  * Function: cmdSignOn()
  517.  *
  518.  * Arguments: None
  519.  * 
  520.  * Return: None
  521.  *
  522.  * Description: Called from menu item or toolbar. Passes control to sidebar
  523.  *        panel cmdSignOn() (see SidebarPanel/SidebarPanel.js)
  524. */
  525.  
  526. function cmdSignOn()
  527. {
  528.     //var sidebarframe = top.frames["AppPanel"];
  529.     //var sidebarframe=top.AIMDocumentPath;
  530.     var sidebarframe=getsidebarframe();
  531.  
  532.   if(sidebarframe)
  533.       sidebarframe.cmdPanelSignOn();
  534.   else
  535.     dump("XXX Error : no sidebarframe\n");
  536. }
  537.  
  538. /*
  539.  * Function: cmdSignOff()
  540.  *
  541.  * Arguments: None
  542.  * 
  543.  * Return: None
  544.  *
  545.  * Description: Calls aimSessionLogoff to close current IM session. 
  546.  *     
  547.  *
  548. */
  549.  
  550. function cmdSignOff()
  551. {
  552.     aimSessionLogoff();
  553. }
  554.  
  555. /*
  556.  * Function: cmdCancelSignOn()
  557.  *
  558.  * Arguments: None
  559.  * 
  560.  * Return: None
  561.  *
  562.  * Description: Called during connection startup if cancel button is pressed.
  563.  *         Cancels the IM session by calling cmdSignOff().
  564.  *        
  565. */
  566.  
  567. function cmdCancelSignOn()
  568. {
  569.     cmdSignOff();
  570. }
  571.  
  572. /*
  573.  * Function: cmdClose()
  574.  *
  575.  * Arguments: None
  576.  * 
  577.  * Return: None
  578.  *
  579.  * Description: Invoked from close menu item, or from cmdSignOffAndClose(),
  580.  *        below. Causes the app window to be closed.
  581.  *
  582. */
  583.  
  584. function cmdClose()
  585. {
  586.    aimCmdClose();
  587. }
  588.  
  589. /*
  590.  * Function: cmdSignOffAndClose()
  591.  *
  592.  * Arguments: None
  593.  * 
  594.  * Return: None
  595.  *
  596.  * Description: Called in response to user selecting signoff and close menu
  597.  *        item. Signs off the current IM session and closes the 
  598.  *        standalone window.
  599. */
  600.  
  601. function createInstance( contractid, iidName )
  602. {
  603.     var iid = eval( "Components.interfaces." + iidName );
  604.     return Components.classes[ contractid ].createInstance( iid );
  605. }
  606.  
  607. function cmdExportBuddyList()
  608. {
  609.     var fileSpec = createInstance( "@mozilla.org/filespecwithui;1", "nsIFileSpecWithUI" );
  610.        var url;    
  611.     try {
  612.         fileSpec.chooseOutputFile(aimString("title.exportbudlist"), 
  613.             "buddy_list.blt", fileSpec.eTextFiles + fileSpec.eAllFiles);
  614.     }
  615.     catch( e ) {
  616.         // no biggie
  617.     }
  618.     if(fileSpec && fileSpec.isValid()) {
  619.         var status;
  620.  
  621.         status = aimBuddyExportBuddyList(fileSpec);
  622.         if ( status == false )
  623.             aimErrorBox(aimString("msg.exporttryagain"));
  624.         else
  625.             aimErrorBox(aimString("msg.exportsuccess"));
  626.     } else 
  627.         aimErrorBox(aimString("msg.exportfailure"));
  628. }
  629.  
  630.  
  631. function cmdImportBuddyList()
  632. {
  633.     var fileSpec = createInstance( "@mozilla.org/filespecwithui;1", "nsIFileSpecWithUI" );
  634.        var url;    
  635.     try {
  636.         fileSpec.chooseInputFile( aimString("title.importbudlist"),
  637.             fileSpec.eAllFiles, 
  638.             aimString("budlist.seamonkeybudlist"), "*.blt");
  639.     }
  640.     catch( e ) {
  641.         // no biggie
  642.     }
  643.     if(fileSpec) {
  644.         if (fileSpec.isValid() && fileSpec.isFile()) {
  645.             var status;
  646.             status = aimBuddyImportBuddyList(fileSpec);
  647.             if ( status == false )
  648.                 aimErrorBox(aimString("msg.importtryagain"));
  649.             else
  650.                 aimErrorBox(aimString("msg.importsuccess"));
  651.         }
  652.         else
  653.             aimErrorBox(aimString("msg.importfailure"));
  654.     }
  655.     else
  656.         aimErrorBox(aimString("msg.importfailure"));
  657. }
  658.  
  659. function cmdSignOffAndClose()
  660. {
  661.     cmdSignOff();
  662.     cmdClose();
  663. }
  664.  
  665. /*
  666.  * Function: cmdAddBuddy()
  667.  *
  668.  * Arguments: None
  669.  * 
  670.  * Return: None
  671.  *
  672.  * Description: Called in response to menu item of toolbar button in standalone
  673.  *        for adding a buddy to a buddy group. Opens BuddyAddBuddy.xul to
  674.  *        place a dialog that can be used to add a buddy.
  675.  *
  676.  * Bugs:    Needs to support inline editing.
  677.  * 
  678. */
  679.  
  680. function cmdAddBuddy()
  681. {
  682.     //var sidebarframe = top.frames["AppPanel"];
  683.     //var sidebarframe = window // in new UI land
  684.     
  685.     
  686.     //dump("AIMDocumentPath: "+top.AIMDocumentPath+"\n");
  687.     //sidebarframe=top.AIMDocumentPath;
  688.     var sidebarframe=getsidebarframe();
  689.  
  690.     var foundOne = false;
  691.     var selectedGroup = "";
  692.  
  693.   var elt = sidebarframe;
  694.   if (!sidebarframe)
  695.     elt = window;
  696.   var tree = elt.document.getElementById("ListSetup");
  697.     var groups = aimBuddyTreeFindGroups( tree );
  698.  
  699.     if ( !groups || groups.length == 0 ) {
  700.         aimErrorBox(aimString("msg.NoGroups"));
  701.         return;
  702.     }
  703.     openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", 
  704.         "modal=yes,titlebar,chrome", groups, tree, null);
  705.         
  706.     
  707.         
  708. }
  709.  
  710. /*
  711.  * Function: cmdAddGroup()
  712.  *
  713.  * Arguments: None
  714.  * 
  715.  * Return: None
  716.  *
  717.  * Description: Called in response to menu item of toolbar button in standalone
  718.  *        for adding a buddy group. Opens BuddyAddGroup.xul to place a 
  719.  *        dialog that can be used to add a buddy group.
  720.  *
  721.  * Bugs:    Needs to support inline editing.
  722.  * 
  723. */
  724.  
  725. function cmdAddGroup()
  726. {
  727.     openDialog("chrome://aim/content/BuddyAddGroup.xul", "", "modal=yes,titlebar,chrome");
  728. }
  729.  
  730. /*
  731.  * Function: SelectedGroup()
  732.  *
  733.  * Arguments: None
  734.  * 
  735.  * Return: None
  736.  *
  737.  * Description: Constructor function for SelectedGroup objects
  738.  *         
  739.  *        
  740. */
  741.  
  742. function SelectedGroup()
  743. {
  744.     var selected = "false";
  745.     var name = null;
  746.     var selectedBuddies = null;
  747. }
  748.  
  749. /*
  750.  * Function: SelectedBuddy()
  751.  *
  752.  * Arguments: None
  753.  * 
  754.  * Return: None
  755.  *
  756.  * Description: Constructor function for SelectedBuddy objects
  757.  *         
  758. */
  759.  
  760. function SelectedBuddy()
  761. {
  762.     var selected = "false"
  763.     var name = null;
  764. }
  765.  
  766. /*
  767.  * Function: cmdDelete()
  768.  *
  769.  * Arguments: None
  770.  * 
  771.  * Return: None
  772.  *
  773.  * Description: Called in response to user clicking delete toolbar button or
  774.  *        selecting delete menu item. Deletes all selected groups (and
  775.  *        the buddies they contain) and all selected buddies.
  776. */
  777.  
  778. function cmdDelete()
  779. {    
  780.     // Delete all selected groups and or buddies
  781.  
  782.     //var sidebarframe = top.frames["AppPanel"];
  783.     //var sidebarframe=window // in new UI land
  784.     //sidebarframe=top.AIMDocumentPath;
  785.       var sidebarframe=getsidebarframe();
  786.  
  787.     var selectedGroup = "";
  788.     var wasSelected = false;
  789.  
  790.     var tree = sidebarframe.document.getElementById("ListSetup");
  791.     var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  792.  
  793.     if (!tab)
  794.         return;
  795.     if (!tree )
  796.         return;
  797.  
  798.     if ( tab.getAttribute('index') == 0 ) // in the online tab and the user hit delete
  799.         return;
  800.  
  801.     var groups = aimBuddyTreeFindGroups( tree );
  802. //    dump( "Groups is " + groups + "\n" );
  803. //    dump("Num groups is " + groups.length + "\n");
  804.  
  805.     top.selectedGroups = new Array();
  806.         
  807.     for (var i = 0; i != groups.length; i++) {
  808.  
  809.         // make a record for this group
  810.  
  811.         top.selectedGroups[i] = new SelectedGroup;
  812.         top.selectedGroups[i].selectedBuddies = new Array();
  813.         top.selectedGroups[i].name = groups[i].getAttribute("Name");
  814.         if (groups[i].getAttribute("selected") == "true") {
  815.             wasSelected = "true";
  816.             top.selectedGroups[i].selected = "true";
  817.         }
  818.         else
  819.             top.selectedGroups[i].selected = "false";
  820.  
  821.         // find the buddy nodes for this group.
  822.  
  823.         var buddies = null;
  824.         for (var j = 0; j != groups[i].childNodes.length; j++)
  825.         {
  826.             if (groups[i].childNodes[j].nodeName == "treechildren")
  827.             {
  828.                 // found it.
  829.  
  830.                 buddies = groups[i].childNodes[j].childNodes;
  831.                 break;
  832.             }
  833.         }
  834.  
  835.         // if there were buddies, collect info on them
  836.  
  837.         if (buddies)
  838.         {
  839.             for (var j = 0; j != buddies.length; j++)
  840.             {
  841.                 // create a record for this buddy
  842.  
  843.                 top.selectedGroups[i].selectedBuddies[j] = new SelectedBuddy;
  844.                 if (buddies[j].getAttribute("selected") == "true") {
  845.                     // buddy is selected. Save the name 
  846.                     // and set the selected flag to true
  847.  
  848.                     wasSelected = "true";
  849.                     top.selectedGroups[i].selectedBuddies[j].name = buddies[j].getAttribute("ScreenName");    
  850.                     top.selectedGroups[i].selectedBuddies[j].selected = "true";
  851.                 }
  852.                 else 
  853.                     top.selectedGroups[i].selectedBuddies[j].selected = "false";
  854.             }
  855.         }
  856.     }
  857.  
  858.     // now we have all we need to know. Delete the selected buddies
  859.     // and the selected groups
  860.  
  861.     for ( var i = 0; i != top.selectedGroups.length; i++ ) {
  862.  
  863.         selectedGroup = top.selectedGroups[i].name;
  864.         
  865.         // first the group
  866.  
  867.         if ( top.selectedGroups[i].selected == "true" ) {
  868.             if ( selectedGroup != null && selectedGroup != "" ) {
  869.                 answer = top.confirm(
  870.                     aimString("confirm.DeleteGroup").replace(/%GroupName%/, selectedGroup) );
  871.                 if ( answer == true )
  872.                     aimBuddyRemoveBuddyGroup(selectedGroup);
  873.             }
  874.         }
  875.         else {
  876.             // we didn't delete the group, so see if any buddies
  877.             // in the group need to be deleted.
  878.  
  879.             for ( var j = 0; j != top.selectedGroups[i].selectedBuddies.length; j++ ) {
  880.                 if ( top.selectedGroups[i].selectedBuddies[j].selected == "true" ) {    
  881.                     selectedBuddy = top.selectedGroups[i].selectedBuddies[j].name;
  882.                     if ( selectedBuddy && selectedBuddy != "" ) {
  883. //dump( "Deleting " + selectedBuddy + " from " + selectedGroup + "\n" );
  884.  
  885.                         answer = top.confirm(
  886.                             aimString("confirm.DeleteBuddy").replace(/%BuddyName%/, selectedBuddy).replace(/%GroupName%/, selectedGroup) );
  887.                         if ( answer == true ) 
  888.                             aimBuddyRemoveBuddy(selectedGroup, selectedBuddy);
  889.                     }                    
  890.                 }
  891.             }
  892.         }
  893.     }
  894.  
  895.     if ( wasSelected == false )
  896.         aimErrorBox( aimString("msg.NothingToDelete") );
  897. }
  898.  
  899. function cmdAbEditCard()
  900. {
  901.     //sidebarframe=top.AIMDocumentPath;
  902.         var sidebarframe=getsidebarframe();
  903.         var selectedGroup = "";
  904.         var wasSelected = false;
  905.  
  906.         var tree = sidebarframe.document.getElementById("ListSetup");
  907.     var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");   
  908.      if ( tab.getAttribute('index') == 0 ) // in the online tab and the user hit delete
  909.                 return;
  910.  
  911.         var groups = aimBuddyTreeFindGroups( tree );
  912. //        dump( "Groups is " + groups + "\n" );
  913. //        dump("Num groups is " + groups.length + "\n");
  914.  
  915.         top.selectedGroups = new Array();
  916.  
  917.         for (var i = 0; i != groups.length; i++) {
  918.  
  919.                 // make a record for this group
  920.  
  921.                 top.selectedGroups[i] = new SelectedGroup;
  922.                 top.selectedGroups[i].selectedBuddies = new Array();
  923.                 top.selectedGroups[i].name = groups[i].getAttribute("Name");
  924.                 if (groups[i].getAttribute("selected") == "true") {
  925.                         wasSelected = "true";
  926.                         top.selectedGroups[i].selected = "true";
  927.                 }
  928.                 else
  929.                         top.selectedGroups[i].selected = "false";                                                   // find the buddy nodes for this group.
  930.  
  931.                 var buddies = null;
  932.                 for (var j = 0; j != groups[i].childNodes.length; j++)
  933.                 {
  934.                         if (groups[i].childNodes[j].nodeName == "treechildren")
  935.                         {
  936.                                 // found it.
  937.  
  938.                                 buddies = groups[i].childNodes[j].childNodes;
  939.                                 break;
  940.                         }
  941.                 }
  942.  
  943.  
  944.  
  945.                 if (buddies)
  946.                 {
  947.                         for (var j = 0; j != buddies.length; j++)
  948.                         {
  949.  
  950.                                 top.selectedGroups[i].selectedBuddies[j] = new SelectedBuddy;
  951.                                 if (buddies[j].getAttribute("selected") == "true") {
  952.                                         // buddy is selected. Save the name
  953.                                         // and set the selected flag to true
  954.  
  955.                                         wasSelected = "true";
  956.                                         top.selectedGroups[i].selectedBuddies[j].name = buddies[j].getAttribute("ScreenName");
  957.                                         top.selectedGroups[i].selectedBuddies[j].selected = "true";
  958.                                 }
  959.                                 else
  960.                                         top.selectedGroups[i].selectedBuddies[j].selected = "false";
  961.                         }
  962.                 }                     
  963.          }
  964.  
  965.         for ( var i = 0; i != top.selectedGroups.length; i++ ) {
  966.  
  967.                 selectedGroup = top.selectedGroups[i].name;
  968.  
  969.  
  970.                 if ( top.selectedGroups[i].selected == "true" ) {
  971.                      aimErrorBox(aimString("msg.SelectBuddy")); 
  972.         }
  973.                 else {
  974.                         for ( var j = 0; j != top.selectedGroups[i].selectedBuddies.length; j++ ) {
  975.                          if ( top.selectedGroups[i].selectedBuddies[j].selected == "true" ) {
  976.                              selectedBuddy = top.selectedGroups[i].selectedBuddies[j].name;
  977.                             if ( selectedBuddy && selectedBuddy != "" ) {
  978.             var aimABInfo1= pIIMManager.QueryInterface(Components.interfaces.nsIAimABInfo);
  979.             var abURI= new Object();
  980.             aimABInfo1.GetABURI(selectedBuddy, abURI);
  981.             var abURI = aimABInfo().GetABURI(selectedBuddy);
  982.             var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
  983.             rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
  984.             var card = rdf.GetResource(abURI);
  985.             card = card.QueryInterface(Components.interfaces.nsIAbCard);
  986.         
  987.         //This is not currently suppoerted by AddressBook - ToDO later//
  988.         //var updateview=DisplayCardViewPane(abURI);
  989.         // window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul", "","chrome,resizeable=no,modal",{abURI:"abDirectory://abook.mab",card:card,okCallback:updateView}); 
  990.         //Workaround - Launch addressbook instead of ab card for selected buddy
  991.         //toOpenWindowByType("mail:adressbook", "chrome://messenger/content/addressbook/addressbook.xul");        
  992.         goEditCardDialog("abdirectory://abook.mab",card,null);
  993.                            }
  994.                         }                  
  995.                   }
  996.                 }
  997.                 }
  998.  
  999. }       
  1000.  
  1001.  
  1002. function cmdCustom()
  1003. {
  1004.   url = aimString("app.custom.url");
  1005.   aimCmdNewBrowser(url);
  1006. }
  1007.  
  1008. function cmdAdClick()
  1009. {
  1010.   //var adLink = aimString("app.ad.link");
  1011.       var adLink;
  1012.    if (aimIsShrimp())
  1013.        adLink = aimString("shrimp.ad.link")
  1014.    else
  1015.        adLink = aimString("app.ad.link");
  1016.  
  1017.  
  1018.   var adMini = aimPrefsManager().GetBoolPref("aim.ad.minibrowser", null, true);
  1019.  
  1020.   // adMini will be true only for shrimp
  1021.   if (adMini) {
  1022.     var tearWin = window.open(adLink,adLink,'personalbar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
  1023.     if (window.focus)
  1024.         tearWin.focus();
  1025.   }
  1026.   else    
  1027.       aimCmdNewBrowser(adLink);
  1028. }
  1029.  
  1030. var ad_access=1;
  1031.  
  1032. function setAdTimer()
  1033. {
  1034.  
  1035.   var adButton = top.document.getElementById("adButton");
  1036.  
  1037.   //var adImage = aimString("app.ad.image")+"?access=" + ad_access;
  1038.  
  1039.     var adImage;
  1040.     if (aimIsShrimp())
  1041.         adImage = aimString("shrimp.ad.image")+"?access=" + ad_access
  1042.     else
  1043.         adImage = aimString("app.ad.image")+"?access=" + ad_access;
  1044.   
  1045.   ad_access++;
  1046.   var adTimer = aimString("app.ad.timer");
  1047.  
  1048.   if(adButton) {
  1049.         adButton.setAttribute("src", adImage);
  1050.   }
  1051.  
  1052.   if(window)
  1053.     window.setTimeout('setAdTimer()', adTimer);
  1054. }
  1055.  
  1056. function aboutShrimp(url)
  1057. {
  1058.     var tearWin = window.open(url,url,'personalbar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
  1059.     if (window.focus)
  1060.         tearWin.focus();
  1061. }
  1062.  
  1063. function getSidebarDs()
  1064. {
  1065. var PANELS_RDF_FILE = "UPnls";
  1066. try {
  1067.      var locator_service = Components.classes["@mozilla.org/file/directory_service;1"].getService();
  1068.       if (locator_service)
  1069.         locator_service = locator_service.QueryInterface(Components.interfaces.nsIProperties);
  1070.       var sidebar_file = locator_service.get(PANELS_RDF_FILE, Components.interfaces.nsIFile);
  1071.       if (!sidebar_file.exists()) {
  1072.         //Sidebar panels file does not exist?
  1073.         return;
  1074.       }
  1075.         var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  1076.         file_url.file = sidebar_file;
  1077.         return file_url.spec;
  1078.     } catch (ex) {
  1079.        throw(ex);
  1080.     }
  1081.  }
  1082.  
  1083. function CheckBuddyPanel()
  1084. {
  1085.     var RDF = '@mozilla.org/rdf/rdf-service;1'
  1086.     RDF = Components.classes[RDF].getService();
  1087.     RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
  1088.     var panel_list =RDF.GetDataSource(getSidebarDs()).GetTarget(RDF.GetResource("urn:sidebar:current-panel-list"),RDF.GetResource("http://home.netscape.com/NC-rdf#"+"panel-list"),  true);
  1089.     if (panel_list) {
  1090.         panel_list.QueryInterface(Components.interfaces.nsIRDFResource);
  1091.     }
  1092.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1093.     container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1094.     try { 
  1095.        container.Init(RDF.GetDataSource(getSidebarDs()), panel_list);
  1096.        } catch (ex)
  1097.      {
  1098.       throw(ex);
  1099.      }
  1100.     var panel_resource = RDF.GetResource("urn:sidebar:panel:im-panel");
  1101.     var im_resource=RDF.GetResource("urn:sidebar:3rdparty-panel:chrome://aim/content/SidebarPanel.xul");
  1102.     var panel_index = container.IndexOf(panel_resource);
  1103.     var panel_index2 = container.IndexOf(im_resource);
  1104.     if ((panel_index == -1) && (panel_index2==-1))
  1105.     {
  1106.       if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
  1107.       { 
  1108.          window.sidebar.addPanel ("Buddy List","chrome://aim/content/SidebarPanel.xul",""); 
  1109.       }
  1110.     } 
  1111. }
  1112.